var t, a = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), s = getApp();

Page({
    data: {
        list: [],
        last_page: 1,
        page: 1,
        message_type: "",
        l_id: "",
        timerId: null
    },
    onLoad: function(t) {
        t.l_id && this.setData({
            l_id: t.l_id
        }), this.setData({
            message_type: t.message_type
        });
    },
    onReady: function() {},
    getMessageDate: function(t) {
        var a = new Date(1e3 * t), e = a.getFullYear(), s = a.getMonth() + 1, i = a.getDate();
        return s < 10 && (s = "0".concat(s)), i < 10 && (i = "0".concat(i)), "".concat(e, "-").concat(s, "-").concat(i);
    },
    getData: function() {
        var t = this;
        console.log("请求聊天消息");
        var a = {
            message_type: this.data.message_type
        };
        this.data.l_id && (a.l_id = this.data.l_id), s._postNetWork({
            url: s.getNetAddresss("plugin.lawyer-platform.frontend.controllers.message.getList"),
            data: a,
            success: function(a) {
                1 == a.data.result && (a.data.data.list.data.forEach(function(a) {
                    a.last_msg_time = t.getMessageDate(a.last_msg_time);
                }), t.setData({
                    list: a.data.data.list.data,
                    last_page: a.data.data.list.last_page
                }));
            }
        });
    },
    link: function(t) {
        var a = t.currentTarget.dataset.item, e = {};
        2 == this.data.message_type || 3 == this.data.message_type ? e.chatType = 2 : (e.chatType = 1, 
        e.user_id = a.id), e.message_type = this.data.message_type, e.plugin_name = "lawyer", 
        e.employeeId = a.employee_id, clearInterval(this.data.timerId), this.data.timerId = null, 
        2 == this.data.message_type || 3 == this.data.message_type ? wx.navigateTo({
            url: "/packageH/chitchat/chatWindow/chatWindow?chatType=2&user_id=" + a.uid + "&employeeId=" + a.employee_id + "&plugin_name=lawyer&message_type=" + this.data.message_type + "&queue_id=" + a.id
        }) : wx.navigateTo({
            url: "/packageH/chitchat/chatWindow/chatWindow?chatType=1&user_id=" + wx.getStorageSync("uid") + "&employeeId=" + a.employee_id + "&plugin_name=lawyer&message_type=1"
        });
    },
    onShow: (t = e(a.default.mark(function t() {
        var e = this;
        return a.default.wrap(function(t) {
            for (;;) switch (t.prev = t.next) {
              case 0:
                return t.next = 2, this.getData();

              case 2:
                this.data.timerId = setInterval(function() {
                    e.getData();
                }, 5e3);

              case 3:
              case "end":
                return t.stop();
            }
        }, t, this);
    })), function() {
        return t.apply(this, arguments);
    }),
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        var t = this;
        if (this.data.page >= this.data.last_page) return !1;
        var a = {
            message_type: this.data.message_type
        };
        this.data.l_id && (a.l_id = this.data.l_id), s._postNetWork({
            url: s.getNetAddresss("plugin.lawyer-platform.frontend.controllers.message.getList"),
            data: a,
            success: function(a) {
                1 == a.data.result && (a.data.data.list.data.forEach(function(a) {
                    a.last_msg_time = t.getMessageDate(a.last_msg_time);
                }), t.data.list = t.data.list.concat(a.data.data.list.data), t.setData({
                    list: t.data.list,
                    page: a.data.data.list.current_page,
                    last_page: a.data.data.list.last_page
                }));
            }
        });
    },
    onShareAppMessage: function() {}
});